clear; close all; addpath('../utilities');

if exist('jacobian.mat','file')~=2
    
    para = [0.043682298946	10.680407044771	0.031532285160	25.001413406635	3.812243088585	0.203429573303	0.102423908057	7.945920271541];

    d       = .03;
    spread  = [1-d 1+d];
    G_m     = nan(length(para),length(spread),11);
    
    for i=1:8
        
        for j=1:length(spread)
            
            para_ij = para;
            para_ij(i) = para_ij(i)*spread(j);
            
            G_m(i,j,:) = main_func_SE(para_ij);
            
        end
    end
    
   save jacobian

end

load cov_matrix_infl S_T
W       = pinv(S_T);

load cov_matrix_NW S_T N

load jacobian para G_m spread

dG      = squeeze(G_m(:,2,:) - G_m(:,1,:));
jac     = dG./(para'*(spread(2)-spread(1)));
d       = jac';

col_labels = {'Leverage','Excess return','5-year CDS rate','At-the-money IV','IV skew',...
    'Leverage','Excess returns','5-year CDS rate','At-the-money IV','IV skew','Market return'};

load model_simulation G_m

sen = jac'.*para./G_m';

row_labels = {'$\phi_{\zeta,0}$','$\phi_{\zeta,1}$','$\phi_{\sigma,0}$','$\phi_{\sigma,1}$','$\phi_\mu$','$\omega_0$','$\omega_1$','$\gamma$',};
Opts.Style = 'jf'; Opts.digit='r'; format = '%.2f';
disp(Mat2TexC(sen,format,col_labels,row_labels,[],Opts,'Sensitivity Matrix'))

